import { Component, OnInit, ViewChild } from '@angular/core';
import { environment } from '../../../../environments/environment';
import { _HttpClient } from '@delon/theme';
import { TableCheckPageComponent } from '../../../layout/components/tableCheckPage.component';

@Component({
    selector: 'app-reportform',
    templateUrl: './reportForm.component.html',
    styleUrls: ['./reportForm.component.less']
})

export class ReportFormComponent implements OnInit {
    @ViewChild('tcp', { static: true }) tcp: TableCheckPageComponent;
    searchParam: any = {};
    headData = [];
    plainData = [];
    editModalVisible = false;
    delModalVisible = false;
    tempData = [];
    treeNodeStyle = { 'max-width': '300px', 'max-height': '400px', 'overflow-y': 'auto', 'overflow-x': 'hidden' };
    apiUrl: any = {};
    step = 1;
    childId = '';

    constructor() { }

    ngOnInit() {
        this.loadListMaster();
    }
    detail(id) {
        this.loadListChild(id);
    }
    back() {
        this.loadListMaster();
    }
    loadList() { 
        switch (this.step) {
            case 1:
                this.loadListMaster();
                break;
            case 2:
                this.loadListChild(this.childId);
                break;
        }
    }
    loadListMaster() {
        this.step = 1;
        this.headData = [
            { "name": "处置部门", "width": "10%" },
            { "name": "处置人员", "width": "8%" },
            { "name": "处置时间", "width": "10%" },
            { "name": "应急流程", "width": "15%" },
            { "name": "故障处所", "width": "8%" },
            { "name": "设备类型", "width": "8%" },
            { "name": "设备名", "width": "8%" },
            { "name": "故障时间", "width": "10%" },
            { "name": "故障现象", "width": "" },
            { "name": "操作", "width": "8%" }
        ];
        this.plainData = ["createOrgName", "createUser", "createTime", "procedureName", "faultStationName","devTypeName", "devName", "faultTime", "faultDesc", "detail"];
        this.apiUrl.del = environment.project + '/emerFault/delete';
        this.tcp.loadList(environment.project + '/emerFault/query', '');
    }
    loadListChild(id) {
        this.step = 2;
        this.childId = id;
        this.headData = [
            { "name": "排序", "width": "5%" },
            { "name": "卡控项", "width": "8%" },
            { "name": "卡控内容", "width": "15%" },
            { "name": "卡控要求", "width": "18%" },
            { "name": "响应时间", "width": "7%" },
            { "name": "落实时间", "width": "7%" },
            { "name": "落实情况", "width": "18%" },
            { "name": "备注", "width": "" }
        ];
        this.plainData = ["norder", "item", "content", "require", "startTime", "endTime", "actionInfo", "remark"];
        this.apiUrl.edit = environment.project + '/emerFaultProcedure/update';
        this.tcp.loadList(environment.project + '/emerFaultProcedure/getByFaultId', '&faultId=' + this.childId);
    }
    editModalShow() {
        this.tempData = this.tcp.getAllData();
        this.editModalVisible = true;
    }
    editModalHide() {
        this.editModalVisible = false;
    }
    delModalShow() {
        this.tempData = this.tcp.getAllData();
        this.delModalVisible = true;
    }
    delModalHide() {
        this.delModalVisible = false;
    }
}
